如果學過 Node.js ,可以把它理解為 Node.js 的 http.request
,除了拿來當作爬蟲使用,接下來和各種 API 溝通,甚至模擬登入後的操作,都需要用到它,以下是簡單的範例
var response = UrlFetchApp.fetch('http://www.google.com/');
Logger.log(response.getContentText());
var formData = {
'title': 'Ithelp Ironman 9',
'name': 'Bacon'
};
var options = {
'method': 'post',
'payload': formData
};
var response = UrlFetchApp.fetch('https://httpbin.org/post', options);
Logger.log(response.getContentText());
var formData = {
'title': 'Ithelp Ironman 9',
'name': 'Bacon'
};
var options = {
'method': 'post',
'payload': formData,
'headers': {
Cookie: 'session=aXRoZWxwaXJvbm1hbjl0aA;'
}
};
var res = UrlFetchApp.fetch("https://httpbin.org/headers", options);
Logger.log(response.getContentText());